package yuejian_07.yuejian_07.fragment;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import java.util.List;

import yuejian_07.yuejian_07.R;
import yuejian_07.yuejian_07.RetrofitListener;
import yuejian_07.yuejian_07.adapter.MasterListAdapter;
import yuejian_07.yuejian_07.javabean.Master;
import yuejian_07.yuejian_07.model.MasterModel;

public class HomeQuanweiFragment extends Fragment implements RetrofitListener<List<Master>> {

    private RecyclerView recyclerView;
    private List mDataList;
    private View view=null;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState)
    {
        view=inflater.inflate(R.layout.fragment_homequanwei, container, false);

        initViews();
        getmasterlist();
        return view;

    }
    private void initViews(){

        recyclerView= (RecyclerView)view.findViewById(R.id.rv_quanwei);
        recyclerView.setLayoutManager(new LinearLayoutManager(this.getActivity()));
        recyclerView.setItemAnimator(new DefaultItemAnimator());

    }
    void getmasterlist(){
        MasterModel masterModel=new MasterModel();
        masterModel.masterlist(this);
    }

    @Override
    public void onSuccess(List<Master> data ){

        System.out.printf("data");
        recyclerView.setAdapter(new MasterListAdapter(HomeQuanweiFragment.this.getActivity(),data));
    }

    @Override
    public void onFail(){ Toast.makeText(getActivity(), "网络发生错误", Toast.LENGTH_SHORT).show();}
}


